<template>
	<view class="reply-list-box" v-if="list.length > 0">
		<view class="talk-list">
			<view class="talk-item" :class="index===list.length-1?'':'weui-cell'" v-for="(item, index) in list" :key="index">
				<view class="user-info-box">
					<u-avatar @click="userCenter(item)" size="50" :src="item.avatar"></u-avatar>
					<view class="user-speak-box">
						<view class="user-info">
							<view class="user-name-box">
								<view class="user-name">{{item.nickName}}</view>
								<view class="sex-box-nv" v-if="item.sex == 1">
									<u-icon name="ziyuan2" custom-prefix="iconfont"></u-icon>
									<view class="age-text">{{item.age}}</view>
								</view>
								<view class="sex-box" v-else>
									<u-icon name="ziyuan3" custom-prefix="iconfont"></u-icon>
									<view class="age-text">{{item.age}}</view>
								</view>
							</view>
						</view>
						<view class="content-box">
							<view class="text-box" @longpress="sheet(item)" @click="send(item)">
								<text class="reply-text" v-if="item.replyNickName">
									<text>回复</text>
									<text class="reply-name">{{item.replyNickName}}</text>
									<text class="reply-dot">:</text>
									<text>{{item.content}}</text>
								</text>
								<text v-else>{{item.content}}</text>
							</view>
						</view>
						<view class="time-box">
							<view class="time-text">{{item.time}}</view>
							<view class="toolbar" @click="thumb">
								<u-icon name="thumb-up" size="38"></u-icon>
								<view class="toolbar-text">{{item.giveNum}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="reply-more" @click="more" v-if="yu > 0">展开剩余{{yu}}条回复</view>
		</view>
		<u-action-sheet :list="sheetList" @click="sheetClick" v-model="sheetShow"></u-action-sheet>
	</view>
</template>

<script>
	export default {
		props: {
			dataList: {
				// 动态数据
				type: Array,
				default () {
					return []
				}
			},
			commentId: {
				type: [String],
				default: '-1'
			},
			noticeCommentId: {
				type: [String],
				default: null
			},
			total: {
				type: [Number],
				default: 0
			},
		},
		data() {
			return {
				replyId: '-1',
				pageNum: 1,
				pageSize: 10,
				isEnd: false,
				sum: 0,
				yu: 0,
				list: [],
				sheetList: [{
					text: '删除评论',
					color: 'blue',
					fontSize: 28
				}],
				sheetShow: false,
			}
		},
		created() {
			this.list = this.dataList;
			this.yu = this.total;
		},
		methods: {
			thumb() {
				this.$u.toast('点赞');
			},
			load() {
				this.query();
			},
			query() {
				this.pageNum = 1;
				this.list = [];
				this.isEnd = false;
				this.loadmore();
			},
			addUnshift(data) {
				this.list.unshift(data);
			},
			sheetClick() {
				this.$u.get('/wq/reply/delete',{
					id: this.replyId
				}).then(res => {
					this.query();
				})
			},
			sheet(item) {
				var userId = uni.getStorageSync("userId");
				if(item.userId == userId){
					this.replyId = item.id;
					this.sheetShow = true;
				}
			},
			userCenter(item) {
				if(this.my){
					return;
				}
				this.$u.route({
					url: 'packgeMine/pages/center/index',
					params: {
						userId: item.userId,
					}
				});
			},
			more() {
				this.loadmore();
			},
			async loadmore() {
				if(this.isEnd){
					return;
				}
				var res = await this.getDataList();
				this.list = this.list.concat(res.rows);
				this.yu = this.sum - this.list.length;
			},
			async getDataList() {
				var res = await this.$u.get('/wq/reply/list', {
					pageNum: this.pageNum,
					commentId: this.commentId,
					noticeCommentId: this.noticeCommentId,
					pageSize: this.pageSize,
				});
				this.sum = res.total;
				var totalPage = Math.ceil(res.total/this.pageSize);
				this.pages = totalPage;
				this.pageNum ++;
				if(this.pageNum > this.pages){
					this.isEnd = true;
				}
				return res;
			},
			send(e) {
				this.$emit('reply',e);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.reply-list-box {
		background-color: #f5f5f7;
		border-radius: 10px;
		padding: 5px 0;
		margin-bottom: 10px;
	}
	.talk-list {
	}
	.talk-item {
		margin: 0 5px;
	}
	
	.weui-cell {
	  position: relative;
	}
	
	.weui-cell:after {
	    content: " ";
	    position: absolute;
	    left: 0;
	    bottom: 0;
	    right: 0;
	    height: 1px;
	    border-bottom: 1px solid #e5e5e5;
	    color: #e5e5e5;
	    -webkit-transform-origin: 0 0;
	    transform-origin: 0 0;
	    -webkit-transform: scaleY(0.5);
	    transform: scaleY(0.5);
	    z-index: 2;//看情况使用
	}
	
	.user-speak-box {
		margin-left: 10px;
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	
	.user-info-box {
		display: flex;
		margin-left: 10rpx;
		padding-top: 10px;
		margin-right: 10rpx;
	}
	.user-info {
		display: flex;
		flex-direction: column;
		margin-top: 3px;
		flex: 1;
	}
	.user-name {
		font-size: 28rpx;
		margin-right: 5px;
	}
	.user-woman {
		background-color: #e8bebe;
		display: flex;
		align-items: center;
		border-radius: 100%;
		padding: 3px;
	}
	
	.user-man {
		background-color: #a9c5e2;
		display: flex;
		align-items: center;
		border-radius: 100%;
		padding: 3px;
	}
	.user-name-box {
		display: flex;
		align-items: center;
	}
	.user-tag-box {
		display: flex;
		align-items: center;
		margin-top: 3px;
	}
	.user-tag {
		font-size: 26rpx;
		color: #82848a;
		margin-right: 10px;
	}
	.menu-box {
		display: flex;
	}
	.content-box {
		margin: 5px 0;
		margin-bottom: 0;
	}
	.text-box {
		white-space: pre-wrap;
		display: flex;
		flex-direction: column;
	}
	.toolbar {
		display: flex;
		align-items: center;
		margin-left: 20px;
		color: #82848a;
	}
	.toolbar-text {
		font-size: 26rpx;
		margin-left: 5px;
	}
	.time-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 10px;
		margin-bottom: 10px;
	}
	.time-text {
		font-size: 26rpx;
		color: #82848a;
	}
	.reply-text {
		display: flex;
	}
	.reply-name {
		font-weight: bolder;
	}
	.reply-dot {
		margin-right: 10px;
	}
	.reply-more {
		font-size: 24rpx;
		font-weight: bolder;
		margin-left: 90rpx;
		padding-bottom: 10px;
	}
	.sex-box {
		background-color: #2b85e4;
		display: flex;
		color: #fff;
		padding: 2px 5px;
		border-radius: 20px;
		font-size: 8px;
	}
	.sex-box-nv {
		background-color: #fe709f;
		display: flex;
		color: #fff;
		padding: 2px 5px;
		border-radius: 20px;
		font-size: 8px;
	}
	.age-text {
		margin-left: 2px;
	}
</style>
